<html>
<head><meta charset="utf-8"><title>generic array map · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html">generic array map</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="175899999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175899999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175899999">(Sep 17 2019 at 12:21)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> </p>
<div class="codehilite"><pre><span></span><span class="cp">#![feature(const_fn)]</span><span class="w"></span>
<span class="cp">#![feature(const_generics)]</span><span class="w"></span>
<span class="cp">#![feature(untagged_unions)]</span><span class="w"></span>
<span class="cp">#![feature(const_fn_union)]</span><span class="w"></span>
<span class="cp">#![allow(incomplete_features)]</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">([</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]);</span><span class="w"></span>

<span class="cp">#[derive(Copy,Clone)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Bool</span><span class="p">(</span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">bool_to_Bool</span><span class="p">(</span><span class="n">x</span>: <span class="kt">bool</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Bool</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">Bool</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u8</span><span class="p">)</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">u8_to_u8</span><span class="p">(</span><span class="n">x</span>: <span class="kt">u8</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u8</span> <span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Input</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">Self</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Bool</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Input</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">bool</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">Self</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bool_to_Bool</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">u8</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Input</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">u8</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">Self</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">u8_to_u8</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="n">MAX_ELEMS</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">10</span><span class="p">;</span><span class="w"></span>
<span class="k">union</span> <span class="nc">U</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">elements</span>: <span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">MAX_ELEMS</span><span class="p">],</span><span class="w"></span>
<span class="w">    </span><span class="n">other</span>: <span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">M</span><span class="p">],</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">Foo</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nb">Copy</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">A</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="n">N</span><span class="p">}</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">splat</span><span class="p">(</span><span class="n">x</span>: <span class="nc">T</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">A</span><span class="p">(</span><span class="n">U</span>::<span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="n">N</span><span class="p">}</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">elements</span>: <span class="p">[</span><span class="n">T</span>::<span class="n">M</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"> </span><span class="n">MAX_ELEMS</span><span class="p">]</span><span class="w"> </span><span class="p">}.</span><span class="n">other</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="n">U8x4</span>: <span class="nc">A</span><span class="o">&lt;</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span>::<span class="n">splat</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="n">B8x4</span>: <span class="nc">A</span><span class="o">&lt;</span><span class="n">Bool</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span>::<span class="n">splat</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="175900093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900093">(Sep 17 2019 at 12:22)</a>:</h4>
<p>A couple of issues: </p>
<ul>
<li>one error I get is that pointers are not allowed</li>
</ul>



<a name="175900105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900105">(Sep 17 2019 at 12:22)</a>:</h4>
<blockquote>
<p>error: function pointers are not allowed in const fn</p>
</blockquote>



<a name="175900116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900116">(Sep 17 2019 at 12:22)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=24a31b93faa5a1b39e24100d0bb83758" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=24a31b93faa5a1b39e24100d0bb83758">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=24a31b93faa5a1b39e24100d0bb83758</a></p>



<a name="175900119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900119">(Sep 17 2019 at 12:22)</a>:</h4>
<ul>
<li>then I get an ICE:</li>
</ul>
<blockquote>
<p>error: internal compiler error: src/librustc/ich/impls_ty.rs:209: ty::TyKind::hash_stable() - can't hash a TyVid _#1t.</p>
</blockquote>



<a name="175900140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900140">(Sep 17 2019 at 12:23)</a>:</h4>
<p>that error will disappear with <code>-Zunleash-the-miri-inside-of-you</code></p>



<a name="175900144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900144">(Sep 17 2019 at 12:23)</a>:</h4>
<p>O_o</p>



<a name="175900156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900156">(Sep 17 2019 at 12:23)</a>:</h4>
<p>And if I don't do the weird union transmute thing, but instead try to create an array directly, I get another error saying that I can't create an array using const parameters</p>



<a name="175900158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900158">(Sep 17 2019 at 12:23)</a>:</h4>
<p>the ICE I have no idea about, probably const generics</p>



<a name="175900235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900235">(Sep 17 2019 at 12:24)</a>:</h4>
<p>I'm using <code>-Zunleash-the-miri-inside-of-you</code>, the error with function pointers appears :/</p>



<a name="175900245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900245">(Sep 17 2019 at 12:24)</a>:</h4>
<p>Am I writing the option correctly?</p>



<a name="175900252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900252">(Sep 17 2019 at 12:24)</a>:</h4>
<p>I see the "skipping const checks warnings"</p>



<a name="175900253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900253">(Sep 17 2019 at 12:24)</a>:</h4>
<p>did you use <code>#[feature(const_fn)]</code>?</p>



<a name="175900259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900259">(Sep 17 2019 at 12:24)</a>:</h4>
<p>yes, at the top</p>



<a name="175900263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900263">(Sep 17 2019 at 12:24)</a>:</h4>
<p>ok, odd</p>



<a name="175900266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900266">(Sep 17 2019 at 12:24)</a>:</h4>
<p>(first feature)</p>



<a name="175900270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900270">(Sep 17 2019 at 12:24)</a>:</h4>
<p>not sure what's going on then</p>



<a name="175900279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900279">(Sep 17 2019 at 12:25)</a>:</h4>
<p>const generics are not implemented all the way</p>



<a name="175900282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900282">(Sep 17 2019 at 12:25)</a>:</h4>
<p>I'm assuming that's the problem</p>



<a name="175900306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900306">(Sep 17 2019 at 12:25)</a>:</h4>
<p>I'd like this to work:</p>
<div class="codehilite"><pre><span></span><span class="cp">#![feature(const_generics)]</span><span class="w"></span>
<span class="cp">#![feature(const_fn)]</span><span class="w"></span>
<span class="cp">#![feature(untagged_unions)]</span><span class="w"></span>
<span class="cp">#![feature(const_fn_union)]</span><span class="w"></span>
<span class="cp">#![allow(incomplete_features)]</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">([</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]);</span><span class="w"></span>

<span class="cp">#[derive(Copy,Clone)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Bool</span><span class="p">(</span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">bool_to_Bool</span><span class="p">(</span><span class="n">x</span>: <span class="kt">bool</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Bool</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">Bool</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u8</span><span class="p">)</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">u8_to_u8</span><span class="p">(</span><span class="n">x</span>: <span class="kt">u8</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u8</span> <span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Input</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">Self</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Bool</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Input</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">bool</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">Self</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bool_to_Bool</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">u8</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Input</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">u8</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="nc">fn</span><span class="p">(</span><span class="n">Self</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">u8_to_u8</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">Foo</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nb">Copy</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">A</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="n">N</span><span class="p">}</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">splat</span><span class="p">(</span><span class="n">x</span>: <span class="nc">T</span>::<span class="n">Input</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">A</span><span class="p">([</span><span class="n">T</span>::<span class="n">M</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"> </span><span class="p">{</span><span class="n">N</span><span class="p">}])</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">const</span><span class="w"> </span><span class="n">U8x4</span>: <span class="nc">A</span><span class="o">&lt;</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span>::<span class="n">splat</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="n">B8x4</span>: <span class="nc">A</span><span class="o">&lt;</span><span class="n">Bool</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span>::<span class="n">splat</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="175900312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900312">(Sep 17 2019 at 12:25)</a>:</h4>
<p>(that is, without the weird union transmute thing)</p>



<a name="175900370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900370">(Sep 17 2019 at 12:26)</a>:</h4>
<p>All my other APIs work, but I essentially need to create a [T; MAX_LEN] externally, and use an union to access the [T; N] sub-array..</p>



<a name="175900381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900381">(Sep 17 2019 at 12:26)</a>:</h4>
<p>for some reason that works, but creating the [T; N] array directly does not :D</p>



<a name="175900688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900688">(Sep 17 2019 at 12:31)</a>:</h4>
<p>Huh, I thought that was supposed to work, or is it only for types not for repeat expressions?</p>



<a name="175900818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175900818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175900818">(Sep 17 2019 at 12:32)</a>:</h4>
<p>hmm, apparently not: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=c21ec1c19653beee9444c0e0426a4e23" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=c21ec1c19653beee9444c0e0426a4e23">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=c21ec1c19653beee9444c0e0426a4e23</a></p>



<a name="175902960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175902960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175902960">(Sep 17 2019 at 12:58)</a>:</h4>
<p>It would be good to have nightly features that allow using these in array lengths</p>



<a name="175902971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175902971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175902971">(Sep 17 2019 at 12:59)</a>:</h4>
<p>and also one that allows using function pointers in const fn</p>



<a name="175902997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175902997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175902997">(Sep 17 2019 at 12:59)</a>:</h4>
<p>That would allow playing with these</p>



<a name="175903039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903039">(Sep 17 2019 at 12:59)</a>:</h4>
<blockquote>
<p>It would be good to have nightly features that allow using these in array lengths</p>
</blockquote>
<p>that's like saying it would be good to have a nightly feature for $insert_your_favourite_unimplemented_feature</p>



<a name="175903044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903044">(Sep 17 2019 at 13:00)</a>:</h4>
<p>it's not implemented</p>



<a name="175903087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903087">(Sep 17 2019 at 13:00)</a>:</h4>
<p>the nice error message is just there to prevent ICEs</p>



<a name="175903108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903108">(Sep 17 2019 at 13:00)</a>:</h4>
<p>you can't play with it ;)</p>



<a name="175903127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903127">(Sep 17 2019 at 13:00)</a>:</h4>
<p>there's no implemented feature to play with</p>



<a name="175903136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903136">(Sep 17 2019 at 13:00)</a>:</h4>
<p>I see, I thought miri supported function pointer calls</p>



<a name="175903151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903151">(Sep 17 2019 at 13:00)</a>:</h4>
<p>and that this was just a check preventing them</p>



<a name="175903169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903169">(Sep 17 2019 at 13:00)</a>:</h4>
<p>not that such support for function pointer calls would need to be implemented</p>



<a name="175903207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903207">(Sep 17 2019 at 13:01)</a>:</h4>
<p>(there are workarounds for the array stuff)</p>



<a name="175903222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903222">(Sep 17 2019 at 13:01)</a>:</h4>
<p>oh... -Zunleash-the-miri-inside-of-you actually is that support</p>



<a name="175903234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903234">(Sep 17 2019 at 13:01)</a>:</h4>
<p>it's just not working right :D</p>



<a name="175903237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903237">(Sep 17 2019 at 13:01)</a>:</h4>
<p>feel free to fix it</p>



<a name="175903251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903251">(Sep 17 2019 at 13:02)</a>:</h4>
<p>follow the error message and wrap that in the appropriate check as seen elsewhere in the file</p>



<a name="175903375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903375">(Sep 17 2019 at 13:03)</a>:</h4>
<p>also this works: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=cfdb78fc16f375e8fb013c29aa299c25" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=cfdb78fc16f375e8fb013c29aa299c25">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=cfdb78fc16f375e8fb013c29aa299c25</a></p>



<a name="175903401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903401">(Sep 17 2019 at 13:03)</a>:</h4>
<p>I'm not really sure how that works, but the other code does not :D</p>



<a name="175903519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903519">(Sep 17 2019 at 13:04)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">union</span> <span class="nc">ConstFnArray</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">input</span>: <span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="kt">usize</span>::<span class="n">max_value</span><span class="p">()],</span><span class="w"></span>
<span class="w">    </span><span class="n">output</span>: <span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="175903559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903559">(Sep 17 2019 at 13:05)</a>:</h4>
<p>Now you can create arrays inside <code>const fn</code> as follows <code>ConstFnArray { input [val; _] }.output }</code></p>



<a name="175903645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903645">(Sep 17 2019 at 13:06)</a>:</h4>
<p>The type and length of <code>ConstFnArray::output</code> are properly deduced, so that must already work somehow :D</p>



<a name="175903857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903857">(Sep 17 2019 at 13:08)</a>:</h4>
<p>it works for types</p>



<a name="175903871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175903871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175903871">(Sep 17 2019 at 13:08)</a>:</h4>
<p>just not for the repeat expression</p>



<a name="175904388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175904388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175904388">(Sep 17 2019 at 13:14)</a>:</h4>
<p>ah I see</p>



<a name="175904516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generic%20array%20map/near/175904516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generic.20array.20map.html#175904516">(Sep 17 2019 at 13:15)</a>:</h4>
<p>I'll try to find out what's special about repeat expressions there, and see if I can add a feature gate to enable that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>